package org.ms.mconf.server.springboot.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.ms.mconf.sdk.model.NodeMultiConfig;
import org.ms.mconf.server.springboot.BaseApi;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@RestController
@RequestMapping("acv")
@Api(description = "The Application-Config-Version(ACV) service api")
public class AcvApi extends BaseApi {

    @ApiOperation(value = "gets", notes = "The get all ACV list")
    @RequestMapping(method = RequestMethod.GET)
    public Set<NodeMultiConfig> gets() {
        return super.acvService().query();
    }

    @ApiOperation(value = "publish", notes = "The publish ACV config data")
    @ApiImplicitParam(name = "nodeMultiConfig", value = "The node multi config", required = true, dataType = "NodeMultiConfig", paramType = "body")
    @RequestMapping(value = "{node}/{environment}", method = RequestMethod.POST)
    public boolean publish(@RequestBody NodeMultiConfig nodeMultiConfig) {
        return super.acvService().publish(nodeMultiConfig);
    }

    @ApiOperation(value = "delete", notes = "The delete ACV config by id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "application", value = "The application id", required = true, dataType = "string", paramType = "path"),
            @ApiImplicitParam(name = "config", value = "The config id", required = true, dataType = "string", paramType = "path"),
            @ApiImplicitParam(name = "version", value = "The version id", required = true, dataType = "string", paramType = "path")
    })
    @RequestMapping(value = "{application}/{config}/{version:.+}", method = RequestMethod.DELETE)
    public boolean delete(
            @PathVariable(value = "application", required = false) String application,
            @PathVariable(value = "config", required = false) String config,
            @PathVariable(value = "version", required = false) String version) {
        return super.acvService().delete(new NodeMultiConfig(application, config, version));
    }

}
